package com.xmut.mall.order.controller;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Map;

import com.xmut.mall.order.annotation.CheckJwt;
import com.xmut.mall.order.utils.RespBean;
import com.xmut.mall.order.vo.HandlerPayVo;
import com.xmut.mall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import com.xmut.mall.order.entity.PaymentLogEntity;
import com.xmut.mall.order.service.PaymentLogService;
import com.xmut.mall.order.utils.PageUtils;
import com.xmut.mall.order.utils.R;

@RestController
@RequestMapping("order/paymentlog")
public class PaymentLogController {
    @Autowired
    private PaymentLogService paymentLogService;

    /**
     * 前端定时器5秒一次轮训该接口 查询当前交易的状态
     */
    @CheckJwt
    @PostMapping("/payCallBack")
    public RespBean payCallBack(@RequestBody HandlerPayVo vo){
        return paymentLogService.payCallBack(vo);
    }

    /**
     * 处理支付请求 生成二维码
     *
     */
    @CheckJwt
    @PostMapping("/handlePay")
    public RespBean handlePay(@RequestBody HandlerPayVo vo) {
        return paymentLogService.handlePay(vo);
    }

    /**
     * 进行支付
     */
    @GetMapping("/pay")
    public RespBean pay(@RequestParam("clientType") String clientType,
                        @RequestParam("orderType") String orderType,
                        @RequestParam("paymentClient") String paymentClient,
                        @RequestParam("paymentMethod") String paymentMethod,
                        @RequestParam("price") BigDecimal price,
                        @RequestParam("sn") String sn,
                        @RequestParam("code") String code,
                        @RequestParam("userId") String userId
                        ) {
        HandlerPayVo vo = new HandlerPayVo();
        vo.setClientType(clientType);
        vo.setOrderType(orderType);
        vo.setPaymentClient(paymentClient);
        vo.setPaymentMethod(paymentMethod);
        vo.setPrice(price);
        vo.setSn(sn);
        vo.setUserId(Long.parseLong(userId));
        return paymentLogService.pay(vo,code);
    }
}
